package com.childguo.controller;

import com.childguo.pojo.Stu;
import com.childguo.services.StuService;
import com.childguo.webResult.Result;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;

@Controller
public class WebTransactionController {
    @Autowired
    StuService stuService;

    @RequestMapping("/login")
    @ResponseBody
    public Result<Object> login(HttpServletResponse resp, @RequestParam(name="id",defaultValue = "-1") Integer id, @RequestParam(value = "sname",defaultValue = "None") String sname){
        if(!Objects.equals(sname, "None")){
            Stu stu  = new Stu(id, sname);
            resp.setHeader("Authorization", (String) stuService.selectStuByStu(stu).getData());
            return stuService.selectStuByStu(stu);
        }
        return Result.fail("登陆状态无效",null);
    }

    @RequestMapping("/testIntercept")
    @ResponseBody
    public Result<Object> testIntercept(){
        return Result.success("请求成功",null);
    }
}
